package com.cman777.springc.common.bean.exception;

import com.cman777.springc.common.bean.Iface.ResultCodeEnumI;
import com.cman777.springc.common.bean.enums.BaseResultCodeEnum;
import com.cman777.springc.common.bean.response.JsonResult;
import lombok.Getter;

/**
 * @author chenzhicong
 * @time 2019/11/7 21:43
 * @description
 */
@Getter
public class BusinessException extends RuntimeException {


    private final String code;

    private final String message;


    public BusinessException(String code, String message) {
        super(message, null, false, true);
        this.code = code;
        this.message = message;
    }

    public BusinessException(ResultCodeEnumI resultCodeEnumI) {
        super(resultCodeEnumI.getMessage(), null, false, true);
        this.code = resultCodeEnumI.getCode();
        this.message = resultCodeEnumI.getMessage();
    }

    public BusinessException(JsonResult jsonResult) {
        super(jsonResult.getMessage(), null, false, true);
        this.code = jsonResult.getCode();
        this.message = jsonResult.getMessage();
    }


    public BusinessException(String message) {
        super(message, null, false, true);
        this.code = BaseResultCodeEnum.ERROR.getCode();
        this.message = message;
    }

    @Override
    public String toString() {
        return this.code + ":" + this.message;
    }
}
